#!/bin/bash
set -e
arch=$(uname -m)

## Check the architecture and perform actions accordingly
if [ "$arch" == "x86_64" ]; then
    echo "Detected x86_64 architecture. exec tar -xvf script/migrate.linux-amd64.tar.gz"
    tar -xvf /app/tar/migrate.linux-amd64.tar.gz
elif [ "$arch" == "aarch64" ]; then
    echo "Detected arm64 architecture. exec script/migrate.linux-arm64.tar.gz"
    tar -xvf /app/tar/migrate.linux-arm64.tar.gz
else
    echo "Unsupported architecture: $arch"
    exit 1
fi

/app/migrate -path db/migration -database "postgresql://root:secret@pgservice/cybertwin?sslmode=disable" -verbose up


## 本地安装 migrate
# if [ "$arch" == "x86_64" ]; then
#     echo "Detected x86_64 architecture. exec tar -xvf script/migrate.linux-amd64.tar.gz"
#     tar -xvf "$(dirname "$0")/../tar/migrate.linux-amd64.tar.gz"
# elif [ "$arch" == "aarch64" ]; then
#     echo "Detected arm64 architecture. exec script/migrate.linux-arm64.tar.gz"
#     tar -xvf "$(dirname "$0")/../tar/migrate.linux-amr64.tar.gz"
# else
#     echo "Unsupported architecture: $arch"
#     exit 1
# fi

# mv $(dirname "$0")/../migrate /usr/bin/migrate

# make migrateup
